import { defineStore } from 'pinia'
import { RouteRecordNormalized, useRouter } from 'vue-router'


export const useRouterStore = defineStore('router', {
    state: () => ({
        routes: getRoutes(),
      
    })
})


function getRoutes(){
    const routes = useRouter().getRoutes() as RouteRecordNormalized[]
  const filterRoutes =  routes.filter(route=>route.children.length>0 && route.meta.show).map(r=>{
    r.children = r.children.filter(c=>c.meta?.show)
    return r
  }).filter(r=>r.children.length>0)
  console.log(filterRoutes,'filterRoutes')  
  return filterRoutes

}
